TASK_DIR:=$(dir $(abspath $(lastword $(MAKEFILE_LIST))))

include ../../config.mk

# Inputs
RMD_FILE := $(TASK_DIR)/src/gen_incapacitation_scaled_table.Rmd
CONFIG_FILE := $(TASK_DIR)/hand/config.yaml
MAIN_RESULTS := $(TASK_DIR)/../../run_regressions/output/regression_output__basic.csv
INCAP_SCALED_RATE_RESULTS := $(TASK_DIR)/../../run_regressions/output/regression_output__incapacitation_scaled_rate.csv
INCAP_SCALED_RATE_RESULTS_WINZ_990 := $(TASK_DIR)/../../run_regressions/output/regression_output__incapacitation_scaled_rate_winsorized_990.csv
INCAP_SCALED_RATE_RESULTS_WINZ_995 := $(TASK_DIR)/../../run_regressions/output/regression_output__incapacitation_scaled_rate_winsorized_995.csv
RESULT_FILES := $(MAIN_RESULTS) $(INCAP_SCALED_RATE_RESULTS) $(INCAP_SCALED_RATE_RESULTS_WINZ_990) $(INCAP_SCALED_RATE_RESULTS_WINZ_995)

# One of the outputs
OUT_FILE := $(OUT_DIR)/incapacitation_scaled_rate_up_to_date.tex

$(OUT_FILE): $(RMD_FILE) $(CONFIG_FILE) $(RESULT_FILES) $(OUTCOME_LABELS_FILE) $(TABLE_CONFIG)
	@mkdir -p $(OUT_DIR)
	@mkdir -p $(PAPER_OUT_DIR)
	$(R_script) -e "rmarkdown::render(input = '$(RMD_FILE)')"
	@cp $(OUT_DIR)/*up_to_date.tex $(PAPER_OUT_DIR)

.PHONY: all clean
.DEFAULT_GOAL=all

all: $(OUT_FILE)

clean:
	rm -rf $(OUT_DIR)/*up_to_date*
